<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/2/28
 * Time: 15:30
 */

namespace App;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Category extends Model
{
    use SoftDeletes;
    // 指定表名
    protected $table='category';
    // 开启自动时间戳
    public $timestamps = true;
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    // 追加status_bool字段,status的布尔类型
    public function getStatusBoolAttribute()
    {
        return $this->attributes['status'] ? 'true' : false;
    }

    public function tag()
    {
        return $this->belongsToMany('App\Tag', 'category_mapping_tag', 'category_id', 'tag_id');
    }

    public function category()
    {
        return $this->hasMany('App\Category', 'parent_id', 'id');
    }

    public function swiper()
    {
        return $this->hasOne('App\Swiper', 'category_id', 'id');
    }
}